package com.isoft.dao.flight;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.isoft.entity.flight.FlightInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author LiuGaoMing
 * @version 1.0
 * @description:航班信息数据层
 * @date 2024/6/22 15:29
 */
@Mapper
public interface FlightInfoDao extends BaseMapper<FlightInfo> {
//    通过ID查询飞机的ID，MET_ID,CODE,CFTP从BASE_CFIE表
    @Select("select ID,META_ID,CODE,CFTP,VALID from TEAM04.BASE_CFIE where ID=#{ID}")
    FlightInfo selectFlightInfoByID(Integer ID);

    /**
     * 查询所有飞机的ID，MET_ID,CODE,CFTP从BASE_CFIE表
     * @return
     */
    @Select("select ID,META_ID,CODE,CFTP,VALID from TEAM04.BASE_CFIE")
    List<FlightInfo> selectAllFlightInfo();
//    模糊查询和动态SQL查询：根据飞机的飞机编号CODE、飞机机型CFTP
    @Select({
            "<script> ",
            "SELECT ID, META_ID, CODE, CFTP,VALID ",
            "FROM TEAM04.BASE_CFIE ",
            "<where> ",
            "<if test='CODE != null and CODE != \"\"'> ",
            "AND CODE LIKE CONCAT('%', #{CODE}, '%') ",
            "</if> ",
            "<if test='CFTP != null and CFTP != \"\"'> ",
            "AND CFTP LIKE CONCAT('%', #{CFTP}, '%') ",
            "</if> ",
            "</where> ",
            "</script> "
    })
    List<FlightInfo> selectFlightInfoByCodeOrCftp(@Param("CODE") String CODE, @Param("CFTP") String CFTP);

    /**
     * 根据META_ID去修改CODE、CFTP
     * @param
     * @return
     */
    @Update("update TEAM04.BASE_CFIE set CODE=#{CODE},CFTP=#{CFTP},VALID=#{VALID} where ID=#{ID}")
    int updateFlightInfo(FlightInfo flightInfo);
    /**
     * 分页查询
     */
    @Select("select ID,META_ID,CODE,CFTP,VALID from TEAM04.BASE_CFIE order by id desc limit #{currentPage},#{pageSize}")
    List<FlightInfo> selectFlightInfoByPage(@Param("currentPage") int currentPage, @Param("pageSize") int pageSize);

    @Select("select count(*) from TEAM04.BASE_CFIE")
    Long selectFlightInfoCount();

    /**
     * 根据ID去删除
     * @param ID
     * @return
     */
    @Delete("delete from TEAM04.BASE_CFIE where ID=#{ID}")
    int deleteFlightInfo(Integer ID);
    /**
     * 增加飞机信息
     */
    @Options(useGeneratedKeys = true, keyProperty = "ID")
    @Insert("INSERT INTO TEAM04.BASE_CFIE(META_ID, CODE, CFTP) VALUES(#{META_ID}, #{CODE}, #{CFTP})")
    int insertFlightInfo(FlightInfo flightInfo);

    @Insert("SET IDENTITY_INSERT TEAM04.BASE_CFIE ON")
    void enableIdentityInsert();

    @Insert("SET IDENTITY_INSERT TEAM04.BASE_CFIE OFF")
    void disableIdentityInsert();
}
